package com.dragon.client.controller.avttendance;

import com.dragon.common.model.Insert;
import com.dragon.common.model.ResponseData;
import com.dragon.common.model.Update;
import com.dragon.logical.service.avttendance.IArrangePointsService;
import com.dragon.repository.domain.dto.ArrangePointsDTO;
import com.dragon.repository.domain.vo.ArrangePointsVO;
import com.dragon.repository.entity.ArrangePoints;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 考勤点 前端控制器
 * </p>
 *
 * @author sy
 * @since 2023-07-31
 */
@RestController
@RequestMapping("arrangePoints")
@Api(tags = "考勤点")
public class ArrangePointsController {

    @Autowired
    IArrangePointsService service;

    @GetMapping("list")
    @ApiOperation("获取考勤点列表")
    public ResponseData<List<ArrangePointsDTO>> pointsList(@ApiParam(name = "search", value ="搜索参数",required = false,type = "string")
                                                           @RequestParam(required = false) String search){
        List<ArrangePoints> pointsList = service.pointsList(search);
        return ResponseData.success(ArrangePointsDTO.convertList(pointsList));
    }


    @PostMapping("add")
    @ApiOperation("考勤点添加")
    public ResponseData pointsAdd(@RequestBody @Validated(Insert.class) ArrangePointsVO vo){
        service.pointsAdd(ArrangePointsVO.convert(vo));
        return ResponseData.success();
    }

    @PostMapping("update")
    @ApiOperation("考勤点修改")
    public ResponseData pointsUpdate(@RequestBody @Validated(Update.class) ArrangePointsVO vo){
        service.pointsUpdate(ArrangePointsVO.convert(vo));
        return ResponseData.success();
    }

    @PostMapping("delete")
    @ApiOperation("考勤点删除")
    public ResponseData pointsDelete(@ApiParam(name = "id",value = "考勤点id", required = true, type = "int")
                                     @RequestParam Integer id){
        service.pointsDelete(id);
        return ResponseData.success();
    }

}
